<template>
	<view>

		<!-- 默认工地信息 -->
		<view class="projectDefault_box">
			<!-- 默认工地名称 -->
			<view class="projectInfo_con">
				<view class="projectSwitch">
					<image src="/static/projectIcon.png" mode="" class="projectIcon"></image>
					<view class="projectName">{{defaultWorksite.project_name}}</view>
					<u-icon name="arrow-down-fill" color="#262626" size="32"></u-icon>
				</view>
			</view>

			<!-- 默认工地统计 -->
			<view class="projectStats_con" @click="toAllPage">
				<view class="statsList_con">
					<view class="statsItem">
						<view class="statsLabel">今日记账</view>
						<view class="statsMoney">
							{{todayData.today}}
							<text class="num" >元</text>
						</view>
					</view>
					<view class="statsLine"></view>
					<view class="statsItem">
						<view class="statsLabel">总付款</view>
						<view class="statsMoney">
							{{todayData.total}}
							<text class="num">元</text>
						</view>
						<view class="allBtn">
							查看全部流水
						</view>
					</view>
				</view>
				<view class="statsMoney_con">
					<image src="/static/moneyIcon.png" mode=""></image>
					<text>剩余总工资：{{todayData.nomoney}}(元)</text>
				</view>
			</view>

			<view class="menuError" v-if="isError" @click="errorClick">
				<text>人工付款有偏差，点击查看</text>
				<u-icon name="error-circle-fill" color="#FF2C00" size="32"></u-icon>
			</view>
		</view>

		

		<template v-if="defaultWorksite.role>1">
			<!-- 选择类型 -->
			<view class="billType_box">
				<view class="typeTit">选择类型</view>
				<view class="billType_con">
					<view v-for="(item,index) in billTypeList" :key="index"
						:class="'typeItem '+(billType==item.id?'active':'')" @click="billTypeSelect(item.id)">
						<image :src="'/static/bill/billType'+item.id+(billType==item.id?'_active':'')+'.png'" mode="">
						</image>
						<view class="typeName">{{item.name}}</view>
					</view>
				</view>
			</view>
		</template>

		<!-- 选择工友 -->
		<template v-if="billType==1">
			<view class="recordBox" v-if="defaultWorksite.role>1 && noWorkerTotal>0">
				<view class="recordHead_con">
					<view class="recordNum">
						选择工友
						<!--  · <text>{{noWorkerTotal}}</text> -->
					</view>
					<view class="recordAll" @click="noSelectAll">
						<checkbox color="#327FE8" :checked="noSelectAllStatus" />
						<text>全选</text>
					</view>
				</view>
				<view class="recordBody_con">
					<view class="workerList_con">
						<view class="workerItem" v-for="(item,index) in noWorkerList" :key="index"
							@click="noWorkerSelect(index)">
							<view class="workerAvatar">
								{{item.userInfo.name_str}}
								<view class="workerTick" v-if="item.selected==1"></view>
							</view>
							<view class="workerName">{{item.userInfo.name_str2}}</view>
						</view>
					</view>
				</view>
			</view>
		</template>

		<!-- 选择材料 -->
		<template v-if="billType==2 || billType==3">
			<view class="recordBox" v-if="defaultWorksite.role>1">
				<view class="recordHead_con">
					<view class="recordNum">
						选择材料
					</view>
					<view class="recordAllBtn" v-if="billType==2" @click="goPage('./materialList')">
						<text>添加材料</text>
					</view>
					<view class="recordAllBtn" v-if="billType==3" @click="goPage('./extraList')">
						<text>添加杂费</text>
					</view>
				</view>
				<view class="recordBody_con">
					<view class="workerList_con">
						<view class="workerItem" v-for="(item,index) in (billType==2?clList:zfList)" :key="index"
							@click="cailiaoAndzafei(index)">
							<view class="workerAvatar">
								{{item.name_str2}}
								<view class="workerTick" v-if="item.selected==1"></view>
							</view>
							<view class="workerName">{{item.name_str}}</view>
						</view>
					</view>
				</view>
			</view>
		</template>

		<!-- 间隔槽 -->
		<u-gap height="20" bg-color="#F5F5F5"></u-gap>

		<!-- 选项卡 -->
		<view class="recordTab_box">
			<view class="recordTab_con">
				<view :class="'recordTabItem '+(recordTabIndex==1?'active':'')" @click="tabClick(1)">
					<text>记账</text>
				</view>
				<view :class="'recordTabItem '+(recordTabIndex==2?'active':'')" @click="tabClick(2)">
					<text>记账流水</text>
				</view>
			</view>
		</view>

		<!-- 记账表单 -->
		<view class="handleList_box" v-if="recordTabIndex==1">
			<view class="handleList_con">
				<view class="handleLabel handleLabelMedium">金额：</view>
				<view class="handleList">
					<view class="baoCon">
						<input type="number" :value="cost" @blur="costBlur" placeholder="0.00">
						<text v-if="billType==1">元/人</text>
						<text v-else>元</text>
					</view>
				</view>
			</view>

			<view class="handleList_con">
				<view class="handleLabel handleLabelMedium">日期：</view>
				<view class="handleList">
					<picker style="width: 100%;" mode="date" :value="date" @change="dateChange">
						<view class="pickerCon">
							{{date}}
							<u-icon name="arrow-right" color="#B3B3B3" size="28"></u-icon>
						</view>
					</picker>
				</view>
			</view>

			<view class="handleList_con" v-if="billType==2 || billType==3">
				<view class="handleLabel handleLabelMedium">数量：</view>
				<view class="handleList">
					<view class="inputCon">
						<input type="decimal" :value="num" placeholder="请输入数量" placeholder-class="placeholderColor"
							@blur="numBlur">
						<input type="decimal" :value="unit" placeholder="请选择单位" placeholder-class="placeholderColor"
							disabled @click="unitClick">
					</view>
				</view>
			</view>
			<view class="handleList_con" v-if="billType==4">
				<view class="handleLabel handleLabelMedium">给款人：</view>
				<view class="handleList">
					<view class="payCon">
						<input type="decimal" :value="payName" @blur="payNameBlur" placeholder="点击输入给款人"
							placeholder-class="placeholderColor">
					</view>
				</view>
			</view>
			<template>
				<view class="handleList_con">
					<view class="handleLabel handleLabelMedium">备注：</view>
					<view class="handleList">
						<view class="textareaCon">
							<textarea :value="remark" @blur="remarkBlur" placeholder="请输入备注"
								placeholder-class="placeholderColor" auto-blur="true" 
							cursor-spacing="100"></textarea>
						</view>
					</view>
				</view>
				<view class="handleList_con">
					<view class="handleLabel handleLabelMedium">照片：</view>
					<view class="handleList">
						<view class="uploadList">
							<view class="uploadItem" v-for="(item, index) in imgList" :key="index"
								v-if="imgList.length >0">
								<image :src="item.url" mode="aspectFill" @click="previewImg(item.url)"></image>
								<view class="delPic" @click="deleteImg(index)">
									<u-icon name="close-circle" color="#fa3534" size="50"></u-icon>
								</view>
							</view>
							<view class="uploadItem uploadBtn" @click="openUpload()">
								<u-icon name="camera" color="#BCBCBC" size="50"></u-icon>
							</view>
						</view>
						<!-- <view class="photoCon">
							<image :src="cameraUrl" alt="" @click="openUpload"></image>
						</view> -->
					</view>
				</view>
			</template>

			<!-- 完成记账 -->
			
			<view class="handlePost_con ">
				<view class="completeBtn" @click="addBill('add')">完成记账</view>
			</view>
			<u-gap height="100" bg-color="#fff"></u-gap>
		</view>

		<!-- 记账流水 -->
		<view class="recordHistory_box" v-if="recordTabIndex==2">
			<view class="historyItem" v-for="(item,index) in billList" :key="index">
				<view class="historyHead_con">
					<view class="historyDate">{{item.time_str}}</view>
				</view>
				<view class="recordList_con">
					<view class="recordItem" v-for="(billItem,billIndex) in item.dataList" :key="billIndex" @click="recordEdit(billItem.id,billItem.account_type)">
						<view class="recordAvatar">
							<image :src="'/static/bill/histoyrType'+billItem.account_type+'.png'" mode=""
								@click="allBill(billItem.project_id,billItem.member_id,billItem.pay_name)"></image>
						</view>
						<view class="recordCon" >
							<view class="recordName">
								{{billItem.pay_name}}
								<text class="modify" v-if="billItem.is_edit==1">有修改</text>
								<text class="recorder"
									v-if="billItem.add_uase_name">(记录人:{{billItem.add_uase_name}})</text>
							</view>
							<view class="recordType">
								<text v-if="billItem.account_type==1">人工</text>
								<text v-if="billItem.account_type==2">材料</text>
								<text v-if="billItem.account_type==3">杂费</text>
								<text v-if="billItem.account_type==4">入款</text>
								<text style="margin: 0 10rpx;">|</text>
								{{billItem.add_date}}
							</view>
							<!-- <view class="recordNote" v-if="item.remark">{{item.remark}}</view> -->
						</view>
						<view class="recordWork" >
							<view class="recordMoney">{{billItem.cost}}元</view>
						</view>
						<view class="recordEdit" >
							修改
						</view>
					</view>
				</view>
			</view>

			<!-- 空数据 -->
			<view class="dataEmpty_con" v-if="billList.length==0">
				<u-empty></u-empty>
			</view>
		</view>

		

		<!-- 超支弹窗 -->
		<u-mask :show="overspendShow" z-index="99999999999999">
			<view class="overspendBox">
				<view class="overspendCon">
					<view class="formIcon">
						<image src="/static/img/waringIcon.png" mode=""></image>
					</view>
					<view class="formTit">超支提醒</view>
					<view class="formClass">
						<view class="classItem" v-for="(item,index) in overspendList" :key="index">
							{{item}}
						</view>
					</view>
					<view class="formWarn">本次付款已超支{{overMoney}}元</view>
					<view class="formOverspend_con">
						<view class="submitBtn cancelBtn" @click="overspendShow = false">放弃记账</view>
						<view class="submitBtn continueBtn" @click="submitForm">继续记账</view>
					</view>
				</view>
			</view>
		</u-mask>

		<!-- 上传图片组件 -->
		<Upload v-if="isUpload" type="jizhang" @getImgs="getImgsFunc"></Upload>
		<uploadCamera v-if="isUploadCamera" type="jizhang" @getImgs="getImgsFunc" ></uploadCamera>

	</view>
</template>

<script>
	import Upload from '@/components/upload/uploadAlbum.vue';
	import uploadCamera from '@/components/upload/uploadCamera.vue';
	export default {
		components: {
			Upload,
			uploadCamera,
		},
		data() {
			return {
				// 默认工地信息
				defaultWorksite: JSON.parse(uni.getStorageSync('defaultWorksite')),

				// 日期
				date: this.$util.nowDate(),

				// 未记工的工人
				noWorkerList: [],
				noWorkerTotal: 0,
				noSelectNum: 0,
				noSelectAllStatus: false,
				member_id: '',

				// 记账列表
				billList: [],
				billTotal: 0,

				// 是否有偏差
				isError: '',

				// 记账类型
				billType: 1,
				billTypeList: [{
						'id': 1,
						'name': '人工',
						'remark': '工资、借款等'
					},
					{
						'id': 2,
						'name': '材料',
						'remark': '沙子、水泥等'
					},
					{
						'id': 3,
						'name': '杂费',
						'remark': '伙食费、螺丝等'
					},
					{
						'id': 4,
						'name': '入款',
						'remark': '工程款、奖励等'
					},
				],

				// 选项卡
				recordTabIndex: 1,

				/**
				 * 表单
				 */
				cost: '', //金额
				num: '', //数量
				unit: '', // 单位
				remark: '', //备注
				payName: '', //材料or给款人

				// 上传图片
				isUpload: false,
				isUploadCamera: false,
				imgList: [],

				// 是否有偏差
				isError: '',

				// 修改记账弹窗
				editShow: false,
				billId: '',
				billDetail: {},

				// 超支弹窗
				overspendShow: false,
				overspendList: [],
				overMoney: 0,

				clList: [],
				zfList: [],
				todayData:{
					today:'',
					nomoney:'',
					total:'',
				},
				
				isAddWork:true,
				
				
			}
		},
		onLoad(option) {
			// uni.showLoading({
			// 	title: '加载中'
			// });
			var _this = this;
			_this.getNoWorker();
		},
		onShow() {
			var _this = this;
			_this.getTodayData();
		
			
			//水印相机
			var imgCamera=uni.getStorageSync('imgCamera');
			if(imgCamera){
				_this.imgList = _this.imgList.concat(JSON.parse(imgCamera));
				uni.setStorageSync('imgCamera','');
			}
			
			_this.getBillList();
		
			
		},
		onReady() {
			var _this = this;
			
			_this.getMaterialList();
			
			_this.getCheckCompare();
			
			
			// 获取选择材料的信息
			uni.$on('updateMaterial', function(data) {
				console.log(data);
				_this.payName = data;
			})
			
			// 获取杂费材料的信息
			uni.$on('updateExtra', function(data) {
				console.log(data);
				_this.payName = data;
			})
			
			// 获取单位的信息
			uni.$on('updateUnit', function(data) {
				console.log(data);
				_this.unit = data;
			})
		},
		methods: {
			
			//查看全部的记工流水
			toAllPage(){
				uni.navigateTo({
					url:'/pages/bill/billStatistics?project_id='+this.defaultWorksite.project_id
				})
			},
			// 选择日期
			dateChange: function(e) {
				this.date = e.detail.value;
				this.getNoWorker();
			},

			// 获取未记工的工人
			getNoWorker() {
				var _this = this;
				_this.$u.get('/api/project.member/getList', {
					project_id: _this.defaultWorksite.project_id,
					days: _this.date,
				}).then(res => {
					uni.hideLoading();
					console.log("==获取未记工的工人==");
					// console.log(res);
					var noWorkerList = res.data;
					for (var i = 0; i < noWorkerList.length; i++) {
						// 带班默认不勾选
						if (_this.defaultWorksite.role == 2) {
							noWorkerList[i].selected = 0;
						} else if (_this.defaultWorksite.role == 1) {
							// 工人默认勾选自己
							noWorkerList[i].selected = 1;
							_this.noSelectNum = 1;
						}
					}

					_this.noWorkerList = noWorkerList;
					_this.noWorkerTotal = noWorkerList.length;

					// 缓存未记工的工人
					uni.setStorageSync('noWorkerList', JSON.stringify(noWorkerList));
				}).catch(res => {
					console.log(res);
				})
			},
			
			
			//获取今天的记账数据
			getTodayData() {
				var _this = this;
				_this.$u.get('/api/project.account/getTodayNum', {
					project_id: _this.defaultWorksite.project_id,
					
				}).then(res => {
					_this.todayData=res.data;
				}).catch(res => {
					console.log(res);
				})
			},

			// 工人单选
			noWorkerSelect(index) {
				var _this = this;
				var noWorkerList = _this.noWorkerList;
				
				// if(noWorkerList[index].is_lock==1){
					
				// 	var dateStr=_this.date;
				// 	var dateList=dateStr.split('-');
				// 	uni.showModal({
				// 		title:'数据锁定',
				// 		content:'当前月份数据已经签字，修改前必须先撤销签字，是否去撤销签字？',
				// 		success(res){
				// 			if(res.confirm){
								
				// 				uni.navigateTo({
				// 					url:'/pages/wage/wageHome?member_id='+noWorkerList[index].id+'&project_id='+noWorkerList[index].project_id+'&currentyear='+dateList[0]+'&currentmonth='+dateList[1]
				// 				})
				// 			}
				// 		}
				// 	})
				// 	return;
				// }
				// 设置当前选中的状态
				if (noWorkerList[index].selected == 1) {
					noWorkerList[index].selected = 0;
				} else {
					noWorkerList[index].selected = 1;
				}

				// 判断是否达到全选
				var noSelectNum = 0;
				for (var i = 0; i < noWorkerList.length; i++) {
					if (noWorkerList[i].selected > 0) {
						noSelectNum++;
					}
					
					console.log(noWorkerList[i])
				}
				if (noSelectNum == noWorkerList.length) {
					_this.noSelectAllStatus = true;
				} else {
					_this.noSelectAllStatus = false;
				}

				_this.noWorkerList = noWorkerList;
				_this.noSelectNum = noSelectNum;

				// 缓存未记工的工人
				uni.setStorageSync('noWorkerList', JSON.stringify(noWorkerList));
			},

			// 全选
			noSelectAll() {
				var _this = this;
				var noSelectAllStatus = _this.noSelectAllStatus;
				noSelectAllStatus = !noSelectAllStatus;

				var noWorkerList = _this.noWorkerList;
				for (let i = 0; i < noWorkerList.length; i++) {
					if(noWorkerList[i].is_lock==1){
						uni.showModal({
							title:'数据锁定',
							content:'当前月份数据已经签字，修改前必须先撤销签字，是否去撤销签字？',
							success(res){
								if(res.confirm){
									uni.navigateTo({
										url:'/pages/wage/wageHome?member_id='+noWorkerList[i].id+'&project_id='+noWorkerList[i].project_id
									})
								}
							}
						})
						return;
					}
				}
				
				
				for (let i = 0; i < noWorkerList.length; i++) {
					noWorkerList[i].selected = noSelectAllStatus;
					//if(!noSelectAllStatus){
					//noWorkerList[i].selected=0
					noWorkerList[i].num = -1;
					noWorkerList[i].overtime_hour = 0;
					noWorkerList[i].overtime_days = 0;
					_this.workType = 0;
					_this.selectOver = 1;
					_this.overWork = 0;
					//}
				}

				// 判断是否达到全选
				var noSelectNum = 0;
				for (var i = 0; i < noWorkerList.length; i++) {
					if (noWorkerList[i].selected == true) {
						noSelectNum++;
					}
				}
				if (noSelectNum == noWorkerList.length) {
					_this.noSelectAllStatus = true;
				} else {
					_this.noSelectAllStatus = false;
				}

				_this.noWorkerList = noWorkerList;
				_this.noSelectNum = noSelectNum;

				// 缓存未记工的工人
				uni.setStorageSync('noWorkerList', JSON.stringify(noWorkerList));
			},

			// 选项卡切换
			tabClick(val) {
				var _this = this;
				_this.recordTabIndex = val;
				_this.clearData();
			},

			// 页面跳转
			goPage(url) {
				uni.navigateTo({
					url: url
				})
			},

			// 获取材料列表
			getMaterialList() {
				var _this = this;
				_this.$u.get('/api/project.accountset/getListAll', {
					project_id: _this.defaultWorksite.project_id,
				}).then(res => {
					console.log("==获取材料列表==")
					console.log(res)
					var zfList = res.data.zafei;
					for (var i = 0; i < zfList.length; i++) {
						zfList[i].selected = false;
					}
					_this.zfList = zfList;

					var clList = res.data.cailiao;
					for (var i = 0; i < clList.length; i++) {
						clList[i].selected = false;
					}
					_this.clList = clList;
				}).catch(res => {
					console.log(res);
				})
			},

			// 选择记账分类
			billTypeSelect(type) {
				console.log("==选择记账分类==")
				console.log(type)
				var _this = this;
				_this.billType = type;
				_this.recordTabIndex=1
				_this.getBillList();
			},

			// 获取金额
			costBlur(e) {
				this.cost = e.detail.value;
			},

			// 选择单位
			unitClick() {
				uni.navigateTo({
					url: './unitList'
				})
			},

			// 获取备注
			remarkBlur(e) {
				this.remark = e.detail.value;
			},

			// 获取数量
			numBlur(e) {
				this.num = e.detail.value;
			},

			// 获取给款人
			payNameBlur(e) {
				this.payName = e.detail.value;
			},

			// 上传图片
			openUpload() {
				var _this = this;
				// #ifdef APP-PLUS
				uni.showActionSheet({
					itemList: ['摄像机', '相册选择'],
					success: function(res) {
						if (res.tapIndex == 0) {
							_this.isUploadCamera = true;
						}
						// if (res.tapIndex == 1) {
						// 	uni.navigateTo({
						// 		// url: '/pages/watermarkCamera/imgCamera'
						// 		url: '/pages/watermarkCamera/watermarkCamera'
						// 	})
						// }
						if (res.tapIndex == 1) {
							_this.isUpload = true;
						}
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
				return
				// #endif
				uni.showActionSheet({
					itemList: ['照相机', '水印相机', '相册选择'],
					success: function (res) {
						if(res.tapIndex==0){
							_this.isUploadCamera = true;
						}
						if(res.tapIndex==1){
							uni.navigateTo({
								url:'/pages/watermarkCamera/imgCamera'
							})
						}
						if(res.tapIndex==2){
							_this.isUpload = true;
						}
						
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});
			},
			
			// 获取上传的图片
			getImgsFunc(e) {
				let _this = this;
				if (e && typeof(e) != 'undefined') {
					_this.imgList = _this.imgList.concat(e);
				}
				_this.isUpload = false;
				_this.isUploadCamera = false;
			},
			
			// 预览图片
			previewImg(src) {
				let _this = this;
				// console.log(_this.imgList);
				var current = src;
				var imgList = _this.imgList;
				var imagesUrl = [];
				for (var i = 0; i < imgList.length; i++) {
					imagesUrl[i] = imgList[i].url;
				}
				// console.log(imagesUrl)
				uni.previewImage({
					current: current,
					urls: imagesUrl
				})
			},
			
			// 图片删除
			deleteImg(index) {
				// console.log(index);
				let _this = this;
				_this.imgList.splice(index, 1);
			},

			cailiaoAndzafei(index) {
				var _this = this;
				var clList = _this.clList;
				var zfList = _this.zfList;
				var billType = _this.billType;
				for (var i = 0; i < clList.length; i++) {
					clList[i].selected = 0;
				}
				for (var i = 0; i < zfList.length; i++) {
					zfList[i].selected = 0;
				}
				if (billType == 2) {
					clList[index].selected = 1;
					_this.payName = clList[index].name;
				}
				if (billType == 3) {
					zfList[index].selected = 1;
					_this.payName = zfList[index].name;
				}
				_this.clList = clList;
				_this.zfList = zfList;
			},

			// 记一笔
			addBill(type) {	
				var _this = this;
				
			
				var defaultWorksite = _this.defaultWorksite;
				if (_this.billType == 0 && defaultWorksite.role > 1) {
					uni.showToast({
						title: '未选择类型',
						icon: 'error'
					})
					return;
				}

				if (_this.billType == 1 && _this.defaultWorksite.role > 1 && type=='add') {
					// 添加人工
					var memberIds = [];
					var noWorkerList = _this.noWorkerList;
					console.log(noWorkerList)
					for (var i = 0; i < noWorkerList.length; i++) {
						if (noWorkerList[i].selected > 0) {
							
							memberIds.push(noWorkerList[i].id)
						}
					}
					_this.member_id = memberIds.join(',');
					
		
					if (!_this.member_id) {
						uni.showToast({
							title: '请选择工人',
							icon: 'error'
						})
						return;
					}
				}

				if (defaultWorksite.role == 1) {
					_this.billType = 1;
					_this.member_id=defaultWorksite.member_id
				}

				if (!_this.cost) {
					uni.showToast({
						title: '请输入金额',
						icon: 'error'
					})
					return;
				}

				if (_this.billType == 2 || _this.billType == 3) {
					if (!_this.payName) {
						uni.showToast({
							title: '请选择材料',
							icon: 'error'
						})
						return;
					}
				}

				if (_this.billType == 2 || _this.billType == 3) {
					if (!_this.num) {
						uni.showToast({
							title: '请输入数量',
							icon: 'error'
						})
						return;
					}

					if (!_this.unit) {
						uni.showToast({
							title: '请选择单位',
							icon: 'error'
						})
						return;
					}
				}

				if (_this.billType == 4) {
					if (!_this.payName) {
						uni.showToast({
							title: '请输入给款人',
							icon: 'error'
						})
						return;
					}
				}
				
				//只有人工需要预警
				if(_this.billType>1){
					_this.$u.throttle(_this.submitForm, 3000);
					return;
				}
				_this.$u.post('/api/project.account/overspendV2', {
					project_id: _this.defaultWorksite.project_id,
					member_id: _this.member_id,
					cost: _this.cost,
				}).then(res => {
					console.log("==透支检测结果==");
					console.log(res);
					
					
					if (res.data.length > 0) {
						_this.overspendList = res.data;
						_this.overspendShow = true;
						_this.overMoney = res.extend.totalMoney
						_this.getNoWorker();
						_this.getMaterialList();
					}else{
						_this.$u.throttle(_this.submitForm, 3000);
					}
				}).catch(res => {
					_this.isAddWork=true;
					console.log(res);
				})
				
				
				// role:1工人 2带班 3老板
				
			},

			submitForm() {
				var _this = this;
				
				if(!_this.isAddWork){
					return;
				}
				_this.isAddWork=false;
				
				
				_this.overspendShow = false;
				// 上传图片
				let imgList = _this.imgList;
				let imgIds = [];
				for (var i = 0; i < imgList.length; i++) {
					imgIds.push(imgList[i].imgID)
				}
				
				// 工人工地,记人工
				if (_this.defaultWorksite.role == 1) {
					_this.member_id = _this.defaultWorksite.member_id;
				}

				// 编辑
				if (_this.billId > 0) {
					var urlStr = '/api/project.account/edit_do';
				} else {
					var urlStr = '/api/project.account/add_do';
				}

				var postData = {
					id: _this.billId || '',
					account_type: _this.billType, //1人工、2杂费、3材料、4入款
					project_id: _this.defaultWorksite.project_id,
					add_date: _this.date,
					
					pay_type: '', //支付方式
					cost: _this.cost,
					num: _this.num,
					unit: _this.unit,
					pay_name: _this.payName,
					remark: _this.remark,
					imgs: imgIds,
				}
				
				if (_this.billId == 0) {
					postData['member_id']=_this.member_id
				}

				_this.$u.post(urlStr, postData).then(res => {
					console.log(res);
					_this.isAddWork=true;
					uni.showModal({
						content: '记账成功',
						showCancel: false,
					})
					_this.recordTabIndex = '2'; //切换到记账流水
					_this.successDoing();
					_this.clearData();
					_this.getBillList();
					_this.getTodayData();
				}).catch(res => {
					_this.isAddWork=true;
					console.log(res);
				})
			},

			// 记账成功
			successDoing(type) {
				var _this = this;
				_this.getBillList();
				_this.getCheckCompare();
			},

			// 查看全部的记账记录
			allBill(projectId, memberId, keyword) {
				uni.navigateTo({
					url: '/pages/bill/billStatistics/billStatistics?member_id=' + memberId + '&project_id=' +
						projectId + '&keyword=' + keyword
				})
			},

			// 编辑记账
			recordEdit(id, type) {
				console.log(id, type);
				var _this = this;
				// _this.editShow = true;
				// _this.billId = id;
				// _this.billType = type;
				// _this.getBillDetail(id);
				uni.navigateTo({
					url:'/pages/bill/billEdit?id='+id
				})
			},

			// 获取记账详情
			getBillDetail(id) {
				// console.log(id)
				var _this = this;
				_this.$u.get('/api/project.account/getDetail', {
					id: id,
				}).then(res => {
					console.log('获取记账详情')
					console.log(res)
					var billDetail = res.data;
					_this.billDetail = billDetail;
					_this.date = billDetail.add_date;
					_this.member_id = billDetail.member_id;
					_this.cost = billDetail.cost; //金额
					_this.payName = billDetail.pay_name; // 给款人or材料名称
					_this.num = billDetail.num; // 数量
					_this.unit = billDetail.unit; // 单位
					_this.remark = billDetail.remark; //备注
				}).catch(res => {
					console.log(res);
				})
			},

			// 删除记账数据
			delClick() {
				var _this = this;
				uni.showModal({
					title: '提示',
					content: '是否确定删除此记账？',
					success: function(res) {
						if (res.confirm) {
							// console.log('用户点击确定');
							_this.$u.post('/api/project.account/delete_do', {
								id: _this.billId,
							}).then(res => {
								console.log("==删除记工==");
								console.log(res);
								uni.showToast({
									title: res.msg,
									duration: 2000
								});

								//清空历史数据
								_this.clearData();
								_this.editShow = false;
								_this.getBillList();
							}).catch(res => {
								console.log(res);
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},

			// 重置表单
			clearData() {
				var _this = this;
				_this.cost = '';
				_this.num = '';
				_this.unit = ''; // 单位
				_this.remark = ''; //备注
				_this.payName = ''; //给款人or材料名称
				_this.date = _this.$util.nowDate();
				_this.member_id = '';
				_this.imgList = [];

				_this.editShow = false;
				_this.billId = '';
			},

			// 获取记工偏差
			getCheckCompare() {
				var _this = this;
				_this.$u.get('/api/project.compare/checkCompare', {
					project_id: _this.defaultWorksite.project_id,
					type: '2', //1记工、2记账
				}).then(res => {
					uni.hideLoading();
					console.log("==获取记工偏差==");
					console.log(res);
					var resData = res.data;
					if (resData > 0) {
						_this.isError = true;
					} else {
						_this.isError = false;
					}
				}).catch(res => {
					console.log(res);
				})
			},

			// 记账异常
			errorClick() {
				uni.navigateTo({
					url: '/pages/dataError/dataError?type=2'
				})
			},

			// 获取记账列表
			getBillList() {
				var _this = this;
				_this.$u.get('/api/project.account/getListByDate', {
					project_id: _this.defaultWorksite.project_id,
					type: '3',
					billType: _this.billType,
				}).then(res => {
					uni.hideLoading();
					_this.billList = res.data;
					_this.billTotal = res.extend.total;
				}).catch(res => {
					console.log(res);
				})
			},

			// 记账详情
			goDetail(id) {
				uni.navigateTo({
					url: './billDetail?id=' + id
				})
			},

		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped lang="scss">
	// 默认工地信息
	.projectDefault_box {
		padding: 30rpx;
		border-radius: 20rpx;
		background-color: $uni-color-white;
		overflow: hidden;
	}

	.projectInfo_con {
		padding-bottom: 30rpx;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.projectSwitch {
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.projectIcon {
		width: 42rpx;
		height: 42rpx;
	}

	.projectName {
		font-size: 32rpx;
		font-weight: bold;
		color: $uni-color;
		margin: 0 20rpx;
	}

	.projectStats_con {
		overflow: hidden;
	}

	.statsList_con {
		height: 200rpx;
		background: #f0f6ff;
		border: 2rpx solid #cce0ff;
		border-radius: 10rpx 10rpx 0 0;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.projectStats_con .statsItem {
		flex: 1;
		text-align: center;
	}

	.projectStats_con .statsLabel {
		font-size: 28rpx;
		color: #8B8A90;
	}

	.projectStats_con .statsMoney {
		font-size: 56rpx;
		font-weight: bold;
		color: #000;
		margin-top: 20rpx;
	}

	.projectStats_con .statsMoney text {
		font-size: 28rpx;
	}
	.overHout{
		font-size: 28rpx;
		color: #f00;
	}
	.projectStats_con .statsLine {
		width: 2rpx;
		height: 60rpx;
		background-color: #CCE0FF;
	}

	.projectStats_con .statsMoney_con {
		height: 90rpx;
		padding: 0 30rpx;
		background: #327fe8;
		border-radius: 0 0 10rpx 10rpx;
		box-sizing: border-box;
		overflow: hidden;
		display: flex;
		align-items: center;
	}

	.projectStats_con .statsMoney_con image {
		width: 30rpx;
		height: 30rpx;
	}

	.projectStats_con .statsMoney_con text {
		font-size: 28rpx;
		color: #fff;
		margin-left: 20rpx;
	}

	// 偏差提示
	.menuError {
		padding: 30rpx;
		overflow: hidden;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #fff4e1;
	}

	.menuError text {
		color: #FF2C00;
		font-size: 28rpx;
		margin-right: 10rpx;
	}

	// 选择类型
	.billType_box {
		padding: 0 30rpx;
	}

	.typeTit {
		padding: 30rpx 0;
		font-size: 32rpx;
		font-weight: bold;
		color: $uni-color;
	}

	.billType_con {
		padding-bottom: 40rpx;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.typeItem {
		flex: 1;
		text-align: center;
	}

	.typeItem image {
		width: 44rpx;
		height: 44rpx;
	}

	.typeItem .typeName {
		font-size: 28rpx;
		font-weight: bold;
		color: $uni-color-text;
	}

	.typeItem.active .typeName {
		color: $uni-color-active;
	}

	/* 选择工友 */
	.recordBox {
		padding: 0 30rpx;
		background-color: $uni-color-white;
		overflow: hidden;
	}

	.recordHead_con {
		padding: 30rpx 0;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.recordNum {
		font-size: 32rpx;
		font-weight: bold;
		color: #000;
	}

	.recordNum text {
		font-size: 28rpx;
		font-weight: normal;
		margin-left: 10rpx;
	}

	.recordAll {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	
	.recordAllBtn {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #327FE8;
		color: #fff;
		border-radius: 10rpx;
		padding: 6rpx 10rpx;
		font-size: 26rpx;
	}

	.recordAll text {
		margin-left: 6rpx;
	}

	.recordBody_con {
		overflow: hidden;
	}

	.workerList_con {
		overflow: hidden;
		display: flex;
		flex-wrap: wrap;
	}

	.workerItem {
		margin-bottom: 26rpx;
		margin-right: 26rpx;
		overflow: hidden;
	}

	.workerItem:nth-child(6n) {
		margin-right: 0;
	}

	.workerAvatar {
		width: 90rpx;
		height: 90rpx;
		font-size: 28rpx;
		color: $uni-color-white;
		box-sizing: border-box;
		border-radius: 10rpx;
		background: $uni-color-active;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
	}

	.workerAvatar .workerTick {
		width: 90rpx;
		height: 90rpx;
		background: url('/static/keep/workerTick.png') no-repeat center center;
		background-size: cover;
		overflow: hidden;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 10;
	}

	.workerAvatar .workerSet {
		width: 100%;
		height: 30rpx;
		line-height: 30rpx;
		text-align: center;
		color: $uni-color;
		font-size: 20rpx;
		background: url('/static/keep/workerSet.png') no-repeat center center;
		background-size: cover;
		overflow: hidden;
		position: absolute;
		left: 0;
		bottom: 0;
		z-index: 20;
	}

	.workerName {
		text-align: center;
		font-size: 26rpx;
		color: $uni-color;
		overflow: hidden;
		margin-top: 20rpx;
	}

	// 记账流水
	.recordHistory_box {
		padding: 0 30rpx;
	}

	.historyHead_con {
		padding: 30rpx 0;
		border-bottom: 1rpx solid #eee;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.historyDate {
		font-size: 28rpx;
		color: $uni-color;
	}

	.historyStats {
		display: flex;
		align-items: center;
	}

	.historyStats .statsItem {
		margin-right: 30rpx;
		display: flex;
		align-items: center;
	}

	.historyStats .statsItem:last-child {
		margin-right: 0;
	}

	.historyStats .statsType {
		width: 32rpx;
		height: 32rpx;
		line-height: 32rpx;
		text-align: center;
		color: #8B8A90;
		font-size: 24rpx;
		background: #f0f0f0;
		border-radius: 5rpx;
		overflow: hidden;
	}

	.historyStats .statsNum {
		font-size: 28rpx;
		color: $uni-color;
		margin-left: 20rpx;
	}

	.recordList_con {
		// padding: 0 30rpx;
	}

	.recordList_conPop {
		max-height: 800rpx;
		overflow-y: scroll;
	}

	.recordItem {
		padding: 30rpx 0;
		border-bottom: 2rpx solid #f5f5f5;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.recordAvatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.recordAvatar image {
		width: 100%;
		height: 100%;
	}

	.recordCon {
		flex: 2;
		font-size: 32rpx;
		overflow: hidden;
		margin: 0 20rpx;
	}

	.recordName {
		font-size: 32rpx;
	}

	.recordName .modify {
		font-weight: 400;
		font-size: 22rpx;
		color: $uni-color-warning;
		padding:0 10rpx;
		border: 2rpx solid $uni-color-warning;
		border-radius: 14rpx 2rpx 14rpx 0;
		margin-left: 30rpx;
		margin-top: -8rpx;
	}

	.recordName .recorder {
		font-weight: 400;
		font-size: 26rpx;
		color: $uni-color-active;
		padding-left: 10rpx;
	}

	.recordType {
		font-size: 24rpx;
		color: $uni-color-text;
		margin-top: 10rpx;
	}

	.recordNote {
		width: 100%;
		font-size: 24rpx;
		color: #999;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		margin-top: 10rpx;
	}

	.recordWork {
		text-align: center;
		overflow: hidden;
		margin-right: 20rpx;
	}

	.recordMoney {
		font-size: 32rpx;
		font-weight: bold;
		color: #000000;
		overflow: hidden;
	}

	.recordDay {
		font-size: 22rpx;
		color: $uni-color;
		overflow: hidden;
		// margin-top: 10rpx;
	}

	.recordEdit {
		width: 90rpx;
		height: 50rpx;
		line-height: 50rpx;
		text-align: center;
		font-size: 24rpx;
		color: $uni-color-text;
		border: 2rpx solid $uni-color-text;
		border-radius: 10rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	//添加按钮
	.addBtn {
		position: fixed;
		right: 20rpx;
		bottom: 30rpx;
		background-color: $uni-color-active;
		border-radius: 20rpx;
		width: 180rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-weight: bold;
	}

	.addBtn image {
		width: 34rpx;
		height: 34rpx;
		margin-right: 10rpx;
		vertical-align: middle;
		margin-top: -6rpx;
	}

	/* 修改记工弹窗 */
	.keepEdit_box {
		max-height: 90vh;
		overflow-y: scroll;
	}

	.setHead_con {
		padding: 30rpx;
		overflow: hidden;
	}

	.setTit {
		width: 100%;
		font-size: 32rpx;
		font-weight: bold;
		color: $uni-color;
		text-align: center;
	}

	.handleList_box {
		padding: 15rpx 30rpx;
	}

	.handPost_con {
		padding: 30rpx;
		border-top: 1rpx solid #eee;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.delBtn {
		width: 240rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 28rpx;
		color: #FF4241;
		border: 2rpx solid #ff4241;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.saveBtn {
		width: 430rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 28rpx;
		color: #fff;
		background-color: #327FE8;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.handleList_con .baoCon text {
		margin-left: 0rpx;
	}
	
	
	
	// 超支提醒弹窗
	.overspendBox {
		width: 100%;
		height: 100vh;
		position: relative;
		z-index: 99999999999;
	}
	
	.overspendCon {
		width: 550rpx;
		padding: 0 30rpx;
		background: linear-gradient(180deg,#8fb3e8 0%, #FFFFFF 30%);
		border-radius: 20rpx;
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		z-index: 99;
	}
	
	.formIcon {
		text-align: center;
		margin-top: -73rpx;
	}
	
	.formIcon image {
		width: 146rpx;
		height: 146rpx;
	}
	
	.formTit {
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
		padding: 30rpx 0;
	}
	
	.formClass {
		overflow: hidden;
	}
	
	.classItem {
		font-size: 28rpx;
		color: #333;
		text-align: center;
		overflow: hidden;
		margin-bottom: 30rpx;
		position: relative;
	}
	
	
	
	.formWarn {
		font-size: 30rpx;
		color: $uni-color-warning;
		text-align: center;
	}
	
	.formOverspend_con {
		padding: 30rpx 0;
		overflow: hidden;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.continueBtn {
		height: 70rpx;
		line-height:70rpx;
		background:#327FE8;
		color: #fff;
		font-weight: normal;
		// border: 1rpx solid #ccc;
		box-shadow: none;
		padding: 0 10rpx;
		width: 200rpx;
		border-radius: 10rpx;
		text-align: center;
	}
	
	.cancelBtn {
		height: 70rpx;
		line-height:70rpx;
		background:$uni-bg-blod;
		color: #333;
		font-weight: normal;
		// border: 1rpx solid #ccc;
		box-shadow: none;
		padding: 0 10rpx;
		width: 200rpx;
		border-radius: 10rpx;
		text-align: center;
	}
	
	.handlePost_con{
		padding: 50rpx 0;
	}
	
	.handleList_con .textareaCon textarea {
		font-size: 36rpx;
		height: 260rpx;
	}
	
	.allBtn{
		color: #f00;
		font-size: 24rpx;
	}
</style>
